import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { TransformInterceptor } from './interceptor/transform.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  //全局注册成功拦截器
  await app.useGlobalInterceptors(new TransformInterceptor());
  // 全局注册错误的过滤器
  app.useGlobalFilters(new HttpExceptionFilter());
  //允许跨域
  app.enableCors();
  //添加全局路由前缀
  app.setGlobalPrefix('v1');
  //添加swagger支持
  const options = new DocumentBuilder()
    .setTitle('接口文档')
    .setDescription('前端vue3+后台nestJs+Typescript项目')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('docs', app, document);
  await app.listen(8888);
}

bootstrap();
